home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue68 / Clinic / OneToManyClient2U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-01-31  |  2.1 KB  |  77 lines

  1. unit OneToManyClient2U;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Db, DBClient, MConnect, Grids, DBGrids, ActnList, StdCtrls;
  8.  
  9. type
  10.   TClientForm = class(TForm)
  11.     cdsCustomer: TClientDataSet;
  12.     dcOneToManyServer: TDCOMConnection;
  13.     DataSource1: TDataSource;
  14.     DBGrid1: TDBGrid;
  15.     CheckBox1: TCheckBox;
  16.     ActionList1: TActionList;
  17.     actShowPopupGrid: TAction;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure actShowPopupGridExecute(Sender: TObject);
  20.     procedure actShowPopupGridUpdate(Sender: TObject);
  21.   private
  22.     FPopupGrid: TCustomDBGrid;
  23.   end;
  24.  
  25. var
  26.   ClientForm: TClientForm;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TClientForm.FormCreate(Sender: TObject);
  33. var
  34.   I: Integer;
  35.   Pt: TPoint;
  36.   Col: TColumn;
  37. begin
  38.   cdsCustomer.Open;
  39.   //Locate and hide dataset field column
  40.   Col := nil;
  41.   for I := 0 to DBGrid1.Columns.Count - 1 do
  42.     if DBGrid1.Columns[I].Field is TDataSetField then
  43.     begin
  44.       Col := DBGrid1.Columns[I];
  45.       Col.Visible := False;
  46.       Break //There is one dataset field column
  47.     end;
  48.   if not Assigned(Col) then
  49.     raise EDatabaseError.Create(
  50.       'Trouble brewing... dataset field not found');
  51.   //Display popup grid below other grid
  52.   Pt := Point(DBGrid1.Left, DBGrid1.Top + DBGrid1.Height);
  53.   Pt := ClientToScreen(Pt);
  54.   DBGrid1.ShowPopupEditor(Col, Pt.X, Pt.Y);
  55.   //Because the popup grid has been displayed,
  56.   //it remains in existence with the main grid, so
  57.   //save reference to it for later use
  58.   for I := 0 to DBGrid1.ComponentCount - 1 do
  59.     if DBGrid1.Components[I] is TCustomDBGrid then
  60.       FPopupGrid := TCustomDBGrid(DBGrid1.Components[I]);
  61.   if not Assigned(FPopupGrid) then
  62.     raise EDatabaseError.Create(
  63.       'Trouble brewing... popup grid not found')
  64. end;
  65.  
  66. procedure TClientForm.actShowPopupGridExecute(Sender: TObject);
  67. begin
  68.   FPopupGrid.Visible := not actShowPopupGrid.Checked
  69. end;
  70.  
  71. procedure TClientForm.actShowPopupGridUpdate(Sender: TObject);
  72. begin
  73.   actShowPopupGrid.Checked := FPopupGrid.Visible
  74. end;
  75.  
  76. end.
  77.